package com.pl.lc.app.controller;

import com.pl.lc.app.service.UserFeign;
import com.pl.lc.common.config.SystemConfig;
import com.pl.lc.common.param.UserAdd;
import com.pl.lc.common.param.UserLogin;
import com.pl.lc.common.vo.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0
 * @Author 小胤
 * @Date 2024/6/6 15:58
 * @注释 使用Feign远程调用
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserFeign userFeign;

    /**
     * 注册
     *
     * @param userAdd
     * @return
     */
    @RequestMapping("/register")
    public R register(@RequestBody UserAdd userAdd) {
        return userFeign.register(userAdd);
    }

    /**
     * 使用用户名密码登录
     *
     * @param userLogin
     * @return
     */
    @RequestMapping("/loginpass")
    public R loginPass(@RequestBody UserLogin userLogin) {
        return userFeign.loginPass(userLogin);
    }

    /**
     * 使用手机号验证码登录
     *
     * @param userLogin
     * @return
     */
    @RequestMapping("/logincode")
    public R loginCode(@RequestBody UserLogin userLogin) {
        return userFeign.loginCode(userLogin);
    }

    /**
     * 退出登录
     *
     * @param
     * @return
     */
    @RequestMapping("/logout")
    public R logout(HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        return userFeign.logout();
    }
}
